import request from '@/utils/request'
import { ApiModulesRoutes } from '@/consts'

/**
 * 分页查询网关列表
 * @param paramVo
 * @param paramVo.pageNo 页码
 * @param paramVo.pageSize 页大小
 * @param paramVo.keyword 关键词
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiFindGatewayPageByParam = async paramVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/findGatewayPageByParam'
  return request.post(url, paramVo)
}

/**
 * 新增网关
 * @param {Object} gatewayVo
 * @param {String} gatewayVo.name 分组名
 * @param {String} gatewayVo.remark 备注名
 * @returns {Promise<void>}
 */
export const apiAddGateway = async gatewayVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/addGateway'
  return await request.post(url, gatewayVo)
}

/**
 * 获取网关详情
 * @param {String} gatewayId 网关id
 * @returns {Promise<void>}
 */
export const apiFindGroupById = async gatewayId => {
  const url = ApiModulesRoutes.IOT + '/gateway/findGatewayById'
  return await request.get(url, { params: { gatewayId } })
}

/**
 * 修改网关
 * @param {Object} gatewayVo
 * @param {String} gatewayVo.id 网关id
 * @param {String} gatewayVo.name 网关名
 * @param {String} gatewayVo.remark 网关备注
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiUpdateGroup = async gatewayVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/updateGateway'
  return await request.post(url, gatewayVo)
}

/**
 * 删除指定网关
 * @param {String} gatewayId 网关id
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiDelGatewayById = async gatewayId => {
  const url = ApiModulesRoutes.IOT + '/gateway/delGatewayById'
  return await request.get(url, { params: { gatewayId } })
}

/**
 * 添加网关设备关系
 * @param {Array} gatewayDeviceVos
 * @param {String} gatewayDeviceVos.deviceId 设备id
 * @param {String} gatewayDeviceVos.groupId 分组idd
 * @returns {Promise<AxiosResponse<any>>}
 */
export const apiAddGatewayDevice = async gatewayDeviceVos => {
  const url = ApiModulesRoutes.IOT + '/gateway/addGatewayDevice'
  return await request.post(url, gatewayDeviceVos)
}

/**
 * 删除网关设备关系
 * @param  {Object} gatewayDeviceVo
 * @param {String} gatewayDeviceVo.deviceId 设备id
 * @param {String} gatewayDeviceVo.gatewayId 分组id
 * @returns {Promise<void>}
 */
export const apiDelGatewayDevice = async gatewayDeviceVo => {
  const url = ApiModulesRoutes.IOT + '/gateway/delGatewayDevice'
  return await request.post(url, gatewayDeviceVo)
}
